package com.dein.music.service.impl;

import com.dein.music.dao.MusicDao;
import com.dein.music.model.Music;
import com.dein.music.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("musicService")
public class MusicServiceImpl implements MusicService{

    protected MusicDao musicDao;

    @Autowired
    @Qualifier("musicDao")
    public void setMusicDao(MusicDao musicDao) {
        this.musicDao = musicDao;
    }


    @Override
    public boolean addMusic(Music music) {
        try {
            musicDao.addMusic(music);
        }catch (Exception e){
            e.printStackTrace();
            return  false;
        }
        return  true;
    }

    @Override
    public Music getMusicById(Long musicId) {
        try {
            return musicDao.getMusicById(musicId);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public boolean updateMusic(Music music) {
        try {
            musicDao.updateMusic(music);
        }catch (Exception e){
            e.printStackTrace();
            return  false;
        }
        return  true;
    }

    @Override
    public boolean deleteMusic(Long musicId) {
        try {
            musicDao.deleteMusic(musicId);
        }catch (Exception e){
            e.printStackTrace();
            return  false;
        }
        return  true;
    }

    @Override
    public List<Music> getMusicList() {
        try {
            return musicDao.getMusicList();
        }catch (Exception e){
            e.printStackTrace();
            return  null;
        }
    }
}
